package com.bridgeintelligent.tag.bulkload.service.core.chain;

import com.bridgeintelligent.tag.bulkload.api.BulkLoadConfig;
import com.bridgeintelligent.tag.bulkload.service.core.iterator.BulkListIterator;
import com.bridgeintelligent.tag.constants.bulkload.BulkLoadMqMsg;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * Created by JackCheung on 2019/9/20 6:05 PM.
 */
@SuppressWarnings("unchecked")
@Component
public class AddLoadChainHandler extends BaseLoadChainTempleHandler {

    private static final int TYPE = BulkLoadConfig.ADD_TYPE;

    public AddLoadChainHandler() {
        setMsgType(TYPE);
    }

    @Override
    public void loadHook(BulkListIterator listIterator, BulkLoadMqMsg bulkLoadMqMsg, String indexName) {
        super.loadHook(listIterator, bulkLoadMqMsg, indexName);
        while (listIterator.hasNext()) {
            List<String> list = listIterator.subList(BulkLoadConfig.ELEMENT_COUNT);
            List<Map<String, Map<String, Object>>> mapList = list(list, bulkLoadMqMsg.getDimId());
            threadPoolExecutor.handler(indexName, bulkLoadMqMsg.getIndexType(), mapList, null, bulkLoadMqMsg.getType());
        }
        //新增文件
        iDimFreeFileUtils.add(bulkLoadMqMsg.getFilePath(), bulkLoadMqMsg.getOriginalFile(), bulkLoadMqMsg.getDimId());
    }
}
